@@ -43,7 +43,7 @@ public class App extends Application{ |
||
43 | 43 |
if(!checkUsbPermission()){ |
44 | 44 |
Toast.makeText(this,"申请usb权限失败",Toast.LENGTH_SHORT).show(); |
45 | 45 |
} |
46 |
- checkCameraLibs(); |
|
46 |
+// checkCameraLibs(); |
|
47 | 47 |
initImageLoader(); |
48 | 48 |
new PatchManager().patch(this, UrlContainer.PATCH_CONFIG_URL,Constants.APP_PATCH_DIR+ File.separator+"patch-"+BuildConfig.VERSION_NAME+".dex","ai.pai.lensman.patch.PatchesInfoImpl"); |
49 | 49 |
noMedia(); |
@@ -54,11 +54,13 @@ public class App extends Application{ |
||
54 | 54 |
DataOutputStream os = null; |
55 | 55 |
try { |
56 | 56 |
String cmd = "chmod 777 " + getPackageCodePath(); |
57 |
+ String cmd1 = "setenforce 0"; |
|
57 | 58 |
String cmd2 = "chmod -R 0777 /dev/bus/usb" ; |
58 | 59 |
|
59 | 60 |
process = Runtime.getRuntime().exec("su"); // 切换到root帐号 |
60 | 61 |
os = new DataOutputStream(process.getOutputStream()); |
61 | 62 |
os.writeBytes(cmd + "\n"); |
63 |
+ os.writeBytes(cmd1 + "\n"); |
|
62 | 64 |
os.writeBytes(cmd2 + "\n"); |
63 | 65 |
os.writeBytes("exit\n"); |
64 | 66 |
os.flush(); |
@@ -24,8 +24,5 @@ public class CameraJNIInterface { |
||
24 | 24 |
public native int mygpcameraexit(); |
25 | 25 |
public native String mygpcameragetsummary(); |
26 | 26 |
public native String mygpcamerawaitforevent(String foldr_path); |
27 |
- public native int mygpfilenewfromfd(String file_path); |
|
28 |
- public native int mygpcamerafileget(String foldr_path, String file_name); |
|
29 |
- public native int mygpfilefree(); |
|
30 | 27 |
|
31 | 28 |
} |
@@ -28,11 +28,7 @@ public class UploadTask extends AsyncTask<Void, Integer, Boolean> { |
||
28 | 28 |
protected Boolean doInBackground(Void... params) { |
29 | 29 |
for(int k = 0 ; k< 3;k++){ |
30 | 30 |
try { |
31 |
- String dirPath = ai.pai.lensman.utils.Constants.APP_IMAGE_DIR + File.separator + bean.sessionId |
|
32 |
- + File.separator + ai.pai.lensman.utils.Constants.THUMBNAIL_DIR_NAME; |
|
33 |
- File dir = new File(dirPath); |
|
34 |
- dir.mkdirs(); |
|
35 |
- File photo = new File(dir, bean.photoName); |
|
31 |
+ File photo = new File(bean.photoPath); |
|
36 | 32 |
LogHelper.d(TAG, "上传照片 第"+k+"次尝试"+ bean); |
37 | 33 |
if (photo.exists() && photo.isFile()) { |
38 | 34 |
PhotoUploadUtils photoUploadUtils = new PhotoUploadUtils(UrlContainer.PHOTO_UPLOAD_URL + "?timestamp=" + System.currentTimeMillis()); |
@@ -81,9 +81,7 @@ public class PhotoRecyclerAdapter extends RecyclerView.Adapter<PhotoRecyclerAdap |
||
81 | 81 |
return; |
82 | 82 |
} |
83 | 83 |
final PhotoBean item = photoList.get(position); |
84 |
- String path = Constants.APP_IMAGE_DIR + File.separator+item.sessionId+File.separator |
|
85 |
- +Constants.THUMBNAIL_DIR_NAME+File.separator+item.photoName; |
|
86 |
- ImageLoaderUtils.displayLocalImage(path, holder.photo, options); |
|
84 |
+ ImageLoaderUtils.displayLocalImage(item.photoPath, holder.photo, options); |
|
87 | 85 |
int height = width*10/16; |
88 | 86 |
ViewGroup.LayoutParams lp=holder.photo.getLayoutParams(); |
89 | 87 |
lp.width = width; |
@@ -1,30 +1,34 @@ |
||
1 | 1 |
package ai.pai.lensman.session; |
2 | 2 |
|
3 |
-import android.widget.Toast; |
|
3 |
+import android.os.Handler; |
|
4 |
+import android.os.Handler.Callback; |
|
5 |
+import android.os.Message; |
|
6 |
+import android.text.TextUtils; |
|
4 | 7 |
|
5 | 8 |
import com.android.common.utils.LogHelper; |
6 | 9 |
|
7 |
-import java.util.ArrayList; |
|
10 |
+import java.io.File; |
|
8 | 11 |
import java.util.Timer; |
9 | 12 |
import java.util.TimerTask; |
10 | 13 |
|
11 |
-import ai.pai.lensman.App; |
|
12 |
-import ai.pai.lensman.BuildConfig; |
|
13 | 14 |
import ai.pai.lensman.bean.PhotoBean; |
14 | 15 |
import ai.pai.lensman.bean.SessionBean; |
15 |
-import ai.pai.lensman.db.DBService; |
|
16 | 16 |
import ai.pai.lensman.dslr.CameraJNIInterface; |
17 |
+import ai.pai.lensman.service.Constants; |
|
17 | 18 |
|
18 |
-public class SessionInteractor { |
|
19 |
+public class SessionInteractor implements Callback{ |
|
19 | 20 |
|
21 |
+ private Timer photoCaptureTimer; |
|
20 | 22 |
private SessionBean sessionBean; |
21 |
- private Timer timer; |
|
22 | 23 |
private SessionListener listener; |
24 |
+ private String sessionWorkingDirPath; |
|
23 | 25 |
|
24 |
- private long maxId = 0; |
|
25 | 26 |
private boolean isWorking; |
26 | 27 |
private boolean isLastQueryReturned = true; |
27 | 28 |
|
29 |
+ private Handler cameraInitHandler; |
|
30 |
+ private static final int MSG_CAMERA_INIT_EVENT = 1001; |
|
31 |
+ |
|
28 | 32 |
private static final String TAG = "SessionInteractor"; |
29 | 33 |
|
30 | 34 |
public SessionInteractor(SessionBean sessionBean, SessionListener listener) { |
@@ -32,6 +36,21 @@ public class SessionInteractor { |
||
32 | 36 |
this.sessionBean = sessionBean; |
33 | 37 |
} |
34 | 38 |
|
39 |
+ @Override |
|
40 |
+ public boolean handleMessage(Message message) { |
|
41 |
+ if(message.what==MSG_CAMERA_INIT_EVENT){ |
|
42 |
+ int result = CameraJNIInterface.getInstance().mygpcamerainit(); |
|
43 |
+ if(result>=0){ |
|
44 |
+ listener.onSessionStartSuccess(sessionBean.sessionId); |
|
45 |
+ isWorking = true; |
|
46 |
+ startCapture(); |
|
47 |
+ }else{ |
|
48 |
+ cameraInitHandler.sendEmptyMessageDelayed(MSG_CAMERA_INIT_EVENT,1000); |
|
49 |
+ } |
|
50 |
+ } |
|
51 |
+ return false; |
|
52 |
+ } |
|
53 |
+ |
|
35 | 54 |
public interface SessionListener { |
36 | 55 |
void onSessionStartSuccess(String session); |
37 | 56 |
void onSessionStartError(String session); |
@@ -41,41 +60,40 @@ public class SessionInteractor { |
||
41 | 60 |
|
42 | 61 |
public void startSession(){ |
43 | 62 |
LogHelper.d(TAG,"startSession"); |
63 |
+ sessionWorkingDirPath = Constants.APP_IMAGE_DIR + File.separator + sessionBean.sessionId |
|
64 |
+ + File.separator + ai.pai.lensman.utils.Constants.ORIGIN_DIR_NAME; |
|
65 |
+ new File(sessionWorkingDirPath).mkdirs(); |
|
44 | 66 |
|
45 |
- ArrayList<PhotoBean> photoList = DBService.getInstance().getPhotoListBySessionId(sessionBean.sessionId); |
|
46 |
- if(photoList!=null && photoList.size()>0){ |
|
47 |
- for(PhotoBean photoBean : photoList){ |
|
48 |
- if(photoBean.photoId>maxId){ |
|
49 |
- maxId = photoBean.photoId; |
|
50 |
- } |
|
67 |
+ int result = CameraJNIInterface.getInstance().mygpcamerainit(); |
|
68 |
+ if(result>=0){ |
|
69 |
+ listener.onSessionStartSuccess(sessionBean.sessionId); |
|
70 |
+ isWorking = true; |
|
71 |
+ startCapture(); |
|
72 |
+ }else{ |
|
73 |
+ if(cameraInitHandler!=null){ |
|
74 |
+ cameraInitHandler.removeCallbacksAndMessages(null); |
|
75 |
+ cameraInitHandler = null; |
|
51 | 76 |
} |
77 |
+ cameraInitHandler = new Handler(this); |
|
78 |
+ cameraInitHandler.sendEmptyMessageDelayed(MSG_CAMERA_INIT_EVENT,1000); |
|
79 |
+ listener.onSessionStartError(sessionBean.sessionId); |
|
52 | 80 |
} |
53 | 81 |
|
54 |
- listener.onSessionStartSuccess(sessionBean.sessionId); |
|
55 |
- isWorking = true; |
|
56 |
- startCapture(); |
|
57 |
- |
|
58 | 82 |
LogHelper.d(TAG,"startSession sessionStartTask execute"); |
59 | 83 |
} |
60 | 84 |
|
61 | 85 |
public void startCapture() { |
62 |
- int result = CameraJNIInterface.getInstance().mygpcamerainit(); |
|
63 |
- if(result>=0){ |
|
64 |
- LogHelper.d(TAG,"相机信息--->\n"+CameraJNIInterface.getInstance().mygpcameragetsummary()); |
|
65 |
- Toast.makeText(App.getAppContext(),CameraJNIInterface.getInstance().mygpcameragetsummary(),Toast.LENGTH_SHORT).show(); |
|
66 |
- |
|
86 |
+ if(photoCaptureTimer !=null){ |
|
87 |
+ photoCaptureTimer.cancel(); |
|
88 |
+ photoCaptureTimer = null; |
|
67 | 89 |
} |
68 |
- if(timer!=null){ |
|
69 |
- timer.cancel(); |
|
70 |
- timer = null; |
|
71 |
- } |
|
72 |
- timer = new Timer(); |
|
73 |
- timer.schedule(new TimerTask() { |
|
90 |
+ photoCaptureTimer = new Timer(); |
|
91 |
+ photoCaptureTimer.schedule(new TimerTask() { |
|
74 | 92 |
@Override |
75 | 93 |
public void run() { |
76 | 94 |
fetchPhotoTask(); |
77 | 95 |
} |
78 |
- },5000,1000); |
|
96 |
+ },2000,1000); |
|
79 | 97 |
} |
80 | 98 |
|
81 | 99 |
private void fetchPhotoTask(){ |
@@ -87,43 +105,50 @@ public class SessionInteractor { |
||
87 | 105 |
return; |
88 | 106 |
} |
89 | 107 |
|
90 |
- if(BuildConfig.isTestMode){ |
|
91 |
- PhotoBean bean = new PhotoBean(); |
|
92 |
- long milisec = System.currentTimeMillis(); |
|
93 |
- bean.photoName = milisec+".jpg"; |
|
94 |
- bean.photoId = milisec; |
|
95 |
- |
|
96 |
- bean.captureTime = bean.photoId; |
|
97 |
- bean.isRawPhoto = false; |
|
98 |
- bean.uploadStatus = PhotoBean.UploadStatus.STATUS_NO_BEGIN; |
|
99 |
- bean.sessionId = sessionBean.sessionId; |
|
100 |
- bean.lensmanId = sessionBean.lensmanId; |
|
101 |
- bean.sessionSeq = sessionBean.sessionSeq; |
|
102 |
- bean.sessionDate = sessionBean.sessionDate; |
|
103 |
- bean.sessionCreateTime = sessionBean.createTime; |
|
104 |
- //TODO |
|
105 |
- return; |
|
108 |
+ isLastQueryReturned = false; |
|
109 |
+ String photoName = CameraJNIInterface.getInstance().mygpcamerawaitforevent(sessionWorkingDirPath); |
|
110 |
+ if(photoName!=null && photoName.length()>0){ |
|
111 |
+ String sub = photoName.substring(0,1); |
|
112 |
+ if(TextUtils.isDigitsOnly(sub)){ |
|
113 |
+ LogHelper.d(TAG,"fetchPhotoTask new photo found"); |
|
114 |
+ PhotoBean bean = new PhotoBean(); |
|
115 |
+ bean.photoName = photoName; |
|
116 |
+ bean.photoId = Long.parseLong(photoName.substring(0,photoName.lastIndexOf("."))); |
|
117 |
+ bean.captureTime = bean.photoId; |
|
118 |
+ bean.isRawPhoto = true; |
|
119 |
+ bean.uploadStatus = PhotoBean.UploadStatus.STATUS_NO_BEGIN; |
|
120 |
+ bean.sessionId = sessionBean.sessionId; |
|
121 |
+ bean.lensmanId = sessionBean.lensmanId; |
|
122 |
+ bean.sessionSeq = sessionBean.sessionSeq; |
|
123 |
+ bean.sessionDate = sessionBean.sessionDate; |
|
124 |
+ bean.sessionCreateTime = sessionBean.createTime; |
|
125 |
+ bean.photoPath = Constants.APP_IMAGE_DIR+File.separator+photoName; |
|
126 |
+ listener.onSessionPhotoCaptured(bean); |
|
127 |
+ } |
|
106 | 128 |
} |
107 | 129 |
|
108 |
- isLastQueryReturned = false; |
|
109 |
- LogHelper.d(TAG,"fetchPhotoTask starts"); |
|
130 |
+ isLastQueryReturned = true; |
|
110 | 131 |
} |
111 | 132 |
|
112 | 133 |
|
113 | 134 |
|
114 | 135 |
public void endSession(){ |
115 | 136 |
isWorking = false; |
116 |
- if(timer!=null){ |
|
117 |
- timer.cancel(); |
|
118 |
- timer = null; |
|
137 |
+ if(photoCaptureTimer !=null){ |
|
138 |
+ photoCaptureTimer.cancel(); |
|
139 |
+ photoCaptureTimer = null; |
|
119 | 140 |
} |
120 |
- //TODO |
|
141 |
+ CameraJNIInterface.getInstance().mygpcameraexit(); |
|
121 | 142 |
listener.onSessionEnd(sessionBean.sessionId); |
143 |
+ if(cameraInitHandler!=null){ |
|
144 |
+ cameraInitHandler.removeCallbacksAndMessages(null); |
|
145 |
+ cameraInitHandler = null; |
|
146 |
+ } |
|
122 | 147 |
} |
123 | 148 |
|
124 | 149 |
public void deletePhoto(PhotoBean photoBean){ |
125 |
- //TODO |
|
126 | 150 |
LogHelper.d(TAG,"deletePhoto execute "+photoBean); |
151 |
+ new File(photoBean.photoPath).delete(); |
|
127 | 152 |
} |
128 | 153 |
|
129 | 154 |
} |
@@ -10,6 +10,7 @@ import java.util.TimerTask; |
||
10 | 10 |
|
11 | 11 |
import ai.pai.lensman.App; |
12 | 12 |
import ai.pai.lensman.BuildConfig; |
13 |
+import ai.pai.lensman.R; |
|
13 | 14 |
import ai.pai.lensman.bean.PhotoBean; |
14 | 15 |
import ai.pai.lensman.bean.SessionBean; |
15 | 16 |
import ai.pai.lensman.db.DBService; |
@@ -72,13 +73,13 @@ public class SessionPresenter implements SessionContract.Presenter, SessionInter |
||
72 | 73 |
|
73 | 74 |
@Override |
74 | 75 |
public void onSessionStartSuccess(String session) { |
75 |
- sessionView.showToast("session启动成功"); |
|
76 |
+ sessionView.showToast(App.getAppContext().getString(R.string.session_start_success)); |
|
76 | 77 |
LogHelper.d(TAG,"onSessionStartSuccess session启动成功"+session); |
77 | 78 |
} |
78 | 79 |
|
79 | 80 |
@Override |
80 | 81 |
public void onSessionStartError(String session) { |
81 |
- sessionView.showToast("session启动失败"); |
|
82 |
+ sessionView.showToast(App.getAppContext().getString(R.string.session_start_success)); |
|
82 | 83 |
} |
83 | 84 |
|
84 | 85 |
@Override |
@@ -134,4 +134,8 @@ |
||
134 | 134 |
|
135 | 135 |
<string name="check_box_time">请检查手机时间设置是否正确</string> |
136 | 136 |
|
137 |
+ <string name="session_start_success">拍摄启动成功</string> |
|
138 |
+ |
|
139 |
+ <string name="session_start_error">拍摄启动失败,请检查相机及连接线</string> |
|
140 |
+ |
|
137 | 141 |
</resources> |